package com.yidu.action;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.model.LockerBox;
import com.yidu.service.BoxService;
import com.yidu.util.Pages;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author roots
 * @since 2018-10-20
 */
@Controller
@RequestMapping("/box")
public class BoxController {
	@Resource
	BoxService boxService;
	
	/**
	 * 查询所有
	 * @return list
	 */
	@RequestMapping("/selectAll")
	@ResponseBody
	public List<LockerBox> selectAll(LockerBox lockerbox,String curPage){
		Pages pages=new Pages();
		pages.setCurPage(Integer.valueOf(curPage));
		pages.setMaxResult(5);
		//调用service的查询所有
		List<LockerBox> list=boxService.selectAll(lockerbox,pages);
		return list;
	}
	
	
	/**
	 * 增加和修改
	 * @param record
	 * @return int
	 */
	@RequestMapping("/addorupdate")
	@ResponseBody
	public int inserts(LockerBox record) {
		System.out.println("asdasdasdasdasd===="+record.getBoxId());
		//调用service的增加或修改的方法
		return boxService.addorupdate(record);
	}
	
	/**
	 * 上屏
	 * @param locIid
	 * @return lockerbox
	 */
	@RequestMapping("/selectup")
	@ResponseBody
	public LockerBox findIdAll(String boxId) {
		System.out.println("asdasdasd="+boxId);
		//调用根据储物柜查询的方法
		LockerBox lockerbox=boxService.findlIdAll(boxId);
		return lockerbox;
	}
	
	/**
	 * 删除
	 * @param boxId
	 * @return
	 */
	@RequestMapping("/deletes")
	@ResponseBody
	public int deletes(String boxId) {
		System.out.println("sss="+boxId);
		//返回删除的方法
		return boxService.deletes(boxId);
	}
	
	
	/**
	 * 根据地区ID查询下面所有的柜子
	 * @param lockerbox
	 * @return list
	 */
	@RequestMapping("/selectidAll")
	@ResponseBody
	public List<LockerBox> selectidAll(LockerBox lockerbox){
		//调用根据柜子查询所有的方法
		List<LockerBox> list=boxService.selectidAll(lockerbox);
		//进行遍历
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			LockerBox lockerBox = (LockerBox) iterator.next();
			System.out.println("查询所有柜子："+lockerBox.getBoxId());
		}
		return list;
	}
	
	@RequestMapping("/oneup")
	@ResponseBody
	public int oneup(String boxId) {
		//返回修改1状态的方法
		return boxService.oneup(boxId);
	}
	
	/**
	 * 分页
	 * @return
	 */
	@RequestMapping("/findCount2")
	@ResponseBody
	public int findCount2(LockerBox lockerBox,String curPage) {
		int rows=boxService.findCount2(lockerBox);
		Pages page=new Pages();
		page.setCurPage(Integer.valueOf(curPage));
		page.setMaxResult(5);
		page.setTotalRows(rows);
		return page.getTotalPage();
	}
	
	
	@RequestMapping("/selectboxid")
	@ResponseBody
	public LockerBox selectboxid(String boxId) {
		return boxService.selectboxid(boxId);
	}
}

